package com.ts.enterprise.common.consts;

import com.google.common.collect.Lists;
import com.ts.enterprise.exception.BusinessException;
import com.ts.enterprise.exception.ExceptionEnum;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 全局公共常量
 *
 * @author dean
 * @date 2018/10/29
 */
public interface CommonConstant {

    /**
     * 只包含数字字母
     * @param str
     * @return
     */
    static boolean validateNumEnglish(final String str){
        if(StringUtils.isEmpty(str)){
            return Boolean.TRUE ;
        }
        if(str.trim().length()==18){
            boolean matches = str.matches(STR_ENG_PATTERN);
            if (matches){
                return  Boolean.TRUE;
            }
        }
        throw new BusinessException(ExceptionEnum.ID_CARD_EXCEPTION);
    }

    /**
     * 至少包含数字和字母
     * @param str
     * @return
     */
    static boolean validateNumEnglishOther(final String str){
        if(StringUtils.isEmpty(str)){
            return Boolean.TRUE ;
        }
        if(str.trim().length()>=8 && str.trim().length()<=16){
            boolean matches = str.matches(LETTER_REGEX);
            if (matches){
                boolean matches1 = str.matches(DIGIT_REGEX);
                if (matches1){
                    return Boolean.TRUE;
                }
            }
        }
        throw new BusinessException(ExceptionEnum.PASSWORD_UPDATE_EXCEPTION);
    }

    /** 全字母规则 正整数规则*/
    String STR_ENG_PATTERN="^[a-z0-9A-Z]+$";
    String STR_ENG_OTHER_PATTERN="^[0-9A-Za-z]+${8,16}$";
    /** 正整数规则 */
    String POSITIVE_INTEGER_PATTERN = "" ;

    String TEST_SMS_CODE = "888888";
    String OK = "ok";
    Integer OK_CODE = 200;
    //含有数字
    String DIGIT_REGEX = ".*\\d+.*";
    //纯字母
    String CONTAIN_DIGIT_REGEX = ".*[0-9].*";
    //包含字母
    String LETTER_REGEX = ".*[a-zA-Z]+.*";
    //纯中文
    String CONTAIN_LETTER_REGEX = ".*[a-zA-z].*";
    String CONTAIN_LETTER_REGEX_1 = "^([a-zA-Z0-9]){6,20}$";

    /**
     * 不进行保存log的接口请求
     * @return
     */
    static List<String> notSaveLogUrl(){
        List<String> excludeUris = Lists.newArrayList();
        excludeUris.add("ossTokenWithSign");
        excludeUris.add("error");
        excludeUris.add("countNotice");
        excludeUris.add("listPubNoticePage");
        excludeUris.add("/customer/listCategory");
        excludeUris.add("/workflow/getSchedule");
        excludeUris.add("getUserInfoByToken");
        excludeUris.add("listAllUserDep");
        excludeUris.add("/order/listPage");
        return excludeUris;
    }

    /**
     * 不进行保存errorlog的接口请求
     * @return
     */
    static List<String> notSaveErrorMsg(){
        List<String> excludeMsg = Lists.newArrayList();
        excludeMsg.add("未认证");
        excludeMsg.add("无操作权限,请联系管理员");
        return excludeMsg;
    }




    /**
     * 删除标记
     */
    String DEL_FLAG = "is_del";

    /**
     * 超级管理员用户名
     */
    String ADMIN_USER_NAME = "admin";

    /**
     * 公共日期格式
     */
    String MONTH_FORMAT = "yyyy-MM";
    String DATE_FORMAT = "yyyy-MM-dd";
    String DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
    String DATETIME_HOUR_FORMAT = "HH:mm";
    String SIMPLE_HOUR_FORMAT = "yyyy-MM-dd HH:mm";
    String SIMPLE_MONTH_FORMAT = "yyyyMM";
    String SIMPLE_DATE_FORMAT = "yyyyMMdd";
    String SIMPLE_DATETIME_FORMAT = "yyyyMMddHHmmss";
    String SIMPLE_DATE_HOUR_FORMAT = "yyyyMMddHH";
    String SIMPLE_DATE_MIN_FORMAT = "yyyyMMddHHmm";
    String TIME_ZONE_GMT8 = "GMT+8";

    String DEF_USER_USERNAME = "用户昵称";

    String LOCK_KEY_PREFIX = "LOCK_KEY";

    /**
     * 租户id参数
     */
    String TENANT_ID_PARAM = "tenantId";



    String METADATA_VERSION = "version";

    /**
     * 文件分隔符
     */
    String PATH_SPLIT = "/";

    /**
     * 默认页码为1
     */
    Long DEFAULT_PAGE_INDEX = 1L;

    /**
     * 默认页大小为10
     */
    Long DEFAULT_PAGE_SIZE = 10L;

    /**
     * 分页总行数名称
     */
    String PAGE_TOTAL_NAME = "total";

    /**
     * 分页数据列表名称
     */
    String PAGE_RECORDS_NAME = "records";

    /**
     * 分页当前页码名称
     */
    String PAGE_INDEX_NAME = "pageIndex";

    /**
     * 分页当前页大小名称
     */
    String PAGE_SIZE_NAME = "pageSize";

}
